-- UIHeroDetailInfo
-- Create by zouyb
-- 英雄信息界面

require "game/ui/form/hero/UICampInfo"
require "game/ui/form/comment/UIComment"

-- UIHeroDetailInfo继承自Layer
UIHeroDetailInfo = class("UIHeroDetailInfo", function()
    return cc.Layer:create();
end);

function UIHeroDetailInfo.create(classId, openType, goodsId)
    return UIHeroDetailInfo.new(classId, openType, goodsId);
end

local resize;

-- 模型缩放比例
local HERO_MODEL_SCALE = 0.6

-- 构造函数
function UIHeroDetailInfo:ctor(classId, openType, goodsId)
    self:setName("UIHeroDetailInfo");
    self.classId = classId;
    self.openType = openType;

    -- 初始化
    local node = cc.CSLoader:createNode("layout/hero/HeroDetailInfo.csb");
    self:addChild(node);
    self.node = node;
    self.goodsId = goodsId;

    if openType == "market" or openType == "petShop" then
        -- 注册获得焦点的回调
        EventMgr.register("UIHeroDetailInfo", event.FOCUS_CHANGED, function(para)
            if para["get"] == "UIHeroDetailInfo" then
                UIMgr:getCurrentScene().topMenu:show(TOPMENU_FRAME_MONEY, TOPMENU_FRAME_GEM);
            end
        end);
    end

    self:setLocalZOrder(UIMgr.BONUS_NOTIFY_ZORDER + 1);

    -- 滚动容器
    self:initScrollview();

    self.scrollview = findChildByName(self.node, "CT/scrollview");

    self.hero = PetM.getMyPet(self.classId);

    -- 显示英雄模型
    self:createHeroModel();

    -- 注册事件处理回调函数
    self:registerEventCallback()

    -- 注册点击事件
    self:registerTouchEvent();

    -- 重绘界面
    self:redraw(openType);

    resize(self);
end

-- 关注各种事件
function UIHeroDetailInfo:registerEventCallback()
    -- 关注评论数量更新
    EventMgr.register("UIHeroDetailInfo", event.UPDATE_COMMENT_COUNT, function(para)
        if para["commentType"] == "pet_" .. tostring(self.classId) then
            self:checkCommentCount();
        end
    end);

    -- 界面析构后，需要清理下
    self:registerScriptHandler(function(ev)
        if ev == "exit" then
            cclog("UIHeroDetailInfo 界面析构清理");
            EventMgr.removeAll("UIHeroDetailInfo");

            if UIDungeonMgr:getCurLevel() then
                UIDungeonMgr:getCurLevel():showTop();
            end

        elseif ev == "enter" then
            if UIDungeonMgr:getCurLevel() then
                UIDungeonMgr:getCurLevel():hideTop();
            end

            -- 播放界面音效
            AudioM.playFx("ui_open1");
        end
    end);
end

-- 按钮被点击的处理
function UIHeroDetailInfo:registerTouchEvent()
    -- 注册购买按钮点击事件
    local btnBuy = findChildByName(self.node, "BT/buy");
    local function onBuyClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            AudioM.playFx("button_click");

            -- 尝试购买
            self:tryBuy();

            -- 关闭当前界面
            UIMgr.getCurrentScene():removeFormByName("UIHeroDetailInfo");
        end
    end
    btnBuy:addTouchEventListener(onBuyClick);

    -- 评论界面参数
    local data = {
        ["title"] = PetM.query(self.classId, "name"),
        ["type"] = "pet_" .. tostring(self.classId),
    }

    -- 注册评论按钮点击事件
    local btnComment = findChildByName(self.node, "BT/btn_comment");
    local function onCommentClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            AudioM.playFx("button_click");

            -- 打开评论界面
            UIMgr.getCurrentScene():removeFormByName("UIComment");
            local uiComment = UIComment.create(data);
            UIMgr.getCurrentScene():addForm(uiComment);
        end
    end
    btnComment:addTouchEventListener(onCommentClick);
    TextStyleM.setTextStyle(btnComment, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    btnComment:setTitleText(getLocStr("btn_text_new_comment"));

    -- 获取评论数量
    Operation.cmd_get_comment_counts(data.type);

    -- 注册返回按钮点击事件
    local btnBack = findChildByName(self.node, "BT/btn_back");
    local function onBackClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            -- 关闭当前界面
            AudioM.playFx("button_return");
            UIMgr.getCurrentScene():removeFormByName("UIHeroDetailInfo");
        end
    end
    AddBackEventHandler(self, btnBack, onBackClick);
    TextStyleM.setTextStyle(btnBack, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    btnBack:setTitleText(getLocStr("btn_text_back"));
end

-- 尝试购买
function UIHeroDetailInfo:tryBuy()
    if self.openType == "market" then
        if MarketM.isRmbBuy(self.goodsId) then
            -- 真钱购买
                if MarketM.isInlandPayWay() then
                    showInlandPayWay(self.goodsId);
                else
                    MarketM.buyByRmb(self.goodsId);
                end
            return;
        end

        local ret = MarketM.canBuyGoods(self.goodsId)
        if true ~= ret or type(ret) == "string" then
            if "sold_out" == ret then
                -- 该商品已售完
                alert(string.format(getLocStr("market_goods_sold_out"), MarketM.query(self.goodsId, "name")));
            elseif "gem_lack" == ret then
                -- 钻石不足
                showGemLackConfirm();
            elseif type(ret) == "string" then
                -- 有提示语，提示之
                alert(ret);
            else
                -- 其他原因，统一提示失败
                trace("UIHeroDetailInfo", "购买失败，原因：" .. tostring(ret))
                alert(getLocStr("market_buy_fail"));
            end
        end
        -- 购买
        Operation.cmd_buy_goods(self.goodsId);
    elseif self.openType == "petShop" then
        local priceInfo = PetShopM.queryPrice(self.goodsId);

        if ItemM.getAmount(ME.user, priceInfo[2]) < priceInfo[3] then
            -- 用于兑换的荣誉碎片不足
            trace("UIHeroDetailInfo", "兑换失败，原因：" .. ItemM.query(priceInfo[2], "name") .. "不足");
        end

        if ME.user.pets[classId] then
            -- 宠物已激活
            trace("UIHeroDetailInfo", "兑换失败，原因：" .. PetM.query(self.classId, "name") .. "已激活");
        end

        Operation.cmd_pet_shop_exchange(self.goodsId);
    elseif self.openType == "SkyPetShop" then
        local priceInfo = SkyPetShopM.queryPrice(self.goodsId);

        if ItemM.getAmount(ME.user, priceInfo[2]) < priceInfo[3] then
            -- 用于兑换的荣誉碎片不足
            trace("UIHeroDetailInfo", "兑换失败，原因：" .. ItemM.query(priceInfo[2], "name") .. "不足");
        end

        if ME.user.pets[classId] then
            -- 宠物已激活
            trace("UIHeroDetailInfo", "兑换失败，原因：" .. PetM.query(self.classId, "name") .. "已激活");
        end

        Operation.cmd_sky_pet_shop_exchange(self.goodsId);
    elseif self.openType == "activity" then
        -- 活动本公告显示的，啥也不干
    elseif self.openType == "activityShop" then
        -- 活动商店
        local activityId = ActivityM.queryExchange(self.goodsId, "activity");
        Operation.cmd_activity_exchange(activityId, self.goodsId, 1);
    end
end

-- 重绘
function UIHeroDetailInfo:redraw(openType)
    -- 名称
    local heroConfig = PetM.query(self.classId);
    local titleLabel = findChildByName(self.node, "CT/bg_main/title_label");
    titleLabel:setString(PetM.query(self.classId, "name"));
    TextStyleM.setArtWordTitleStyle(titleLabel);

    local starNode = findChildByName(self.node, "CT/bg_main/star_node");

    -- 显示星星
    -- 获取英雄阶位
    local starNum;

    if self.hero then
        starNum = self.hero:getRank();
    else
        starNum = heroConfig.init_rank;
    end
    local maxStarNum = PetM.getMaxUpgradeRank();
    if maxStarNum < 1 then
        maxStarNum = 1;
    end
    if maxStarNum < starNum then
        maxStarNum = starNum;
    end

    -- 生成星星层，直接挂到结点上
    local lightStarPath = "images/ui/symbol/star_large.png";

    -- 如果冈布奥已觉醒，使用橙色的星星
    if AwakeM.isCarved(self.classId) then
        lightStarPath = "images/ui/symbol/star_large3.png";
    end

    local layer = createStarLayer(starNum, lightStarPath);
    if layer then
        starNode:removeAllChildren();
        starNode:addChild(layer);
    end

    -- 购买信息
    local priceLabel = findChildByName(self.node, "CT/price");
    local gemIcon = findChildByName(self.node, "CT/gem_icon");

    -- 第五项为购买信息
    local priceNode = findChildByName(self.scrollview, "info_5");
    priceNode:setVisible(false);
    local priceIcon = findChildByName(priceNode, "type_img");
    local wayLabel  = findChildByName(priceNode, "name_label");
    if openType == "market" then
        -- 商城购买才显示购买信息
        -- 售价
        gemIcon:setVisible(false);
        priceIcon:setVisible(false);
        priceLabel:setVisible(false);
        priceNode:setVisible(false);
        local priceInfo = MarketM.query(self.goodsId, "price");
        local price;

        priceLabel:setVisible(false);
        gemIcon:setVisible(false);
        priceIcon:setVisible(false);

        local isRmb = false;

        if priceInfo.gem then
            -- 钻石
            gemIcon:setVisible(false);

            -- 价格条需要向右偏移一些
            priceLabel:setPositionX(priceLabel:getPositionX() + gemIcon:getContentSize().width + 10);

            price = tostring(priceInfo.gem);
        else
            -- 显示人民币价格
            gemIcon:setVisible(false);
            isRmb = true;
            local sku = MarketM.querySku(self.goodsId);
            if type(sku) ~= 'string' then
                price = tostring(string.format("$%d", priceInfo.rmb));
            else
                price = MarketM.getPriceBySku(sku);
            end
        end

        if isRmb then
            -- 设置货币文本的样式
            setCurrencyTextStyle(priceLabel);
        else
            TextStyleM.setTextStyle(priceLabel, TextStyleM.TEXT_SIZE_SMALL, TextStyleM.TEXT_COLOR_ORANGE, true);
        end

        -- 如果有团购，显示团购信息
        if MarketM.isGroupBuyGoods(self.goodsId) then
            local str = getLocStr("group_buying");
            TextStyleM.setTextStyle(wayLabel, TextStyleM.TEXT_SIZE_SMALL, TextStyleM.TEXT_COLOR_DARK_BROWN, false, nil, nil, nil, nil, nil, nil, TextStyleM.getTextScale(str, 36));
            wayLabel:setString(str);

            -- 团购图标
            priceIcon:loadTexture(getCommonIconPath("group_buy_img"));
        end
    elseif openType == "petShop" then
        -- 兑换信息
        priceNode:setVisible(true);
        local priceInfo = PetShopM.queryPrice(self.goodsId);
        local hasAmount = ItemM.getAmount(ME.user, priceInfo[2]);
        local costDesc = getLocStr("attrib_value_format");
        if hasAmount < priceInfo[3] then
            costDesc = "[red]" .. costDesc .. "[-]"
        end

        local price = string.format(getLocStr("change_cost_scraps3"), ItemM.query(priceInfo[2], "name"), costDesc);
        local priceStr = string.format(price, hasAmount, priceInfo[3]);
        TextStyleM.setTextStyle(wayLabel, TextStyleM.TEXT_SIZE_SMALL, TextStyleM.TEXT_COLOR_DARK_BROWN, false, nil, nil, nil, nil, nil, nil, TextStyleM.getTextScale(priceStr, 36));
        applyString(wayLabel, priceStr);

        -- 兑换的图标
        priceIcon:loadTexture(getCommonIconPath("exchange_img"));
    elseif openType == "SkyPetShop" then
        -- 兑换信息
        priceNode:setVisible(true);
        local priceInfo = SkyPetShopM.queryPrice(self.goodsId);
        local hasAmount = ItemM.getAmount(ME.user, priceInfo[2]);
        local costDesc = getLocStr("attrib_value_format");
        if hasAmount < priceInfo[3] then
            costDesc = "[red]" .. costDesc .. "[-]"
        end

        local price = string.format(getLocStr("change_cost_scraps2"), ItemM.query(priceInfo[2], "name"), costDesc);
        local priceStr = string.format(price, hasAmount, priceInfo[3]);
        TextStyleM.setTextStyle(wayLabel, TextStyleM.TEXT_SIZE_SMALL, TextStyleM.TEXT_COLOR_DARK_BROWN, false, nil, nil, nil, nil, nil, nil, TextStyleM.getTextScale(priceStr, 36));
        applyString(wayLabel, priceStr);

        -- 兑换的图标
        priceIcon:loadTexture(getItemIconPath(ItemM.query(priceInfo[2], "icon")));
        priceIcon:setScale(0.417);
    elseif openType == "activityShop" then
        -- 兑换信息
        priceNode:setVisible(true);
        local priceInfo = ActivityM.queryExchange(self.goodsId, "price");
        local hasAmount = ItemM.getAmount(ME.user, priceInfo[2]);
        local costDesc = getLocStr("attrib_value_format");
        if hasAmount < priceInfo[3] then
            costDesc = "[red]" .. costDesc .. "[-]"
        end

        local price = string.format(getLocStr("change_cost_scraps3"), ItemM.query(priceInfo[2], "name"), costDesc);
        local priceStr = string.format(price, hasAmount, priceInfo[3]);
        TextStyleM.setTextStyle(wayLabel, TextStyleM.TEXT_SIZE_SMALL, TextStyleM.TEXT_COLOR_DARK_BROWN, false, nil, nil, nil, nil, nil, nil, TextStyleM.getTextScale(priceStr, 36));
        applyString(wayLabel, priceStr);

        -- 兑换的图标
        priceIcon:loadTexture(getItemIconPath(ItemM.query(priceInfo[2], "icon")));
        priceIcon:setScale(0.417);
    else
        priceNode:setVisible(false);
        priceLabel:setVisible(false);
        gemIcon:setVisible(false);
    end

    -- 阵营名称
    local campNode = self.scrollview:getChildByName("info_1");
    local campNameLabel = findChildByName(campNode, "name_label");
    local campId = CampM.getPetCamp(self.classId);
    local campName = CampM.query(campId, "name") or "";
    campName = campName .. getLocStr("camp_tip");
    TextStyleM.setTextStyle(campNameLabel, TextStyleM.TEXT_SIZE_SMALL, TextStyleM.TEXT_COLOR_DARK_BROWN, false);
    campNameLabel:setString(campName);

    -- 绘制所属阵营图标
    local campIcon = findChildByName(campNode, "type_img");
    campIcon:loadTexture(getCampSmallIconPath(CampM.getPetCamp(self.classId)));

    -- 注册阵营信息
    local detailImg = findChildByName(campNode, "detail_img");
    detailImg:setVisible(true);
    local function onDetailClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            AudioM.playFx("button_caption");
            UIMgr.getCurrentScene():removeFormByName("UIHeroInfo");
            local uiHeroInfo = UIHeroInfo.create({["classId"] = self.classId, });
            UIMgr.getCurrentScene():addForm(uiHeroInfo);
        end
    end
    detailImg:addTouchEventListener(onDetailClick);

    -- 系别
    -- 显示冈布奥的系别
    local careerNode = self.scrollview:getChildByName("info_2");
    local depNameLabel = findChildByName(careerNode, "name_label");
    local careerIcon = findChildByName(careerNode, "type_img");
    local depId = PetM.query(self.classId, "department_order")[1];
    local depName = CareerM.getDepartmentName(depId);

    if getLang() == "zh" or getLang() == "tw" then
        depName = depName .. getLocStr("career_tip");
    else
        depName = depName .. " " .. getLocStr("career_tip");
    end

    -- self:setTopMenuTextStyle3(depNameLabel);
    TextStyleM.setTextStyle(depNameLabel, TextStyleM.TEXT_SIZE_SMALL, TextStyleM.TEXT_COLOR_DARK_BROWN, false);
    depNameLabel:setString(depName);

    careerIcon:loadTexture(getCareerDepartmentIconPath("department_" .. depId));

    -- 天赋
    self:redrawTalentInfo();

    -- 专属技能
    self:redrawSpecialInfo();

    -- 属性初始化
    self:initProp();

    -- 购买按钮
    local btnBuy = findChildByName(self.node, "BT/buy");
    local hintNode = findChildByName(btnBuy, "hint");
    -- 评论按钮
    local btnComment = findChildByName(self.node, "BT/btn_comment");
    if openType == "market" then
        btnBuy:setTitleText(getLocStr("btn_text_buy"));
        btnBuy:setVisible(true);
        checkBlueBubbleStatus(hintNode, false);
    elseif openType == "petShop" then
        btnBuy:setTitleText(getLocStr("btn_text_recruit2"));
        btnBuy:setVisible(true);
        checkBlueBubbleStatus(hintNode, false);
        local hint2 = findChildByName(btnBuy, "hint2");
        if not PetShopM.canBuyGoods(self.goodsId) then
            -- 无法兑换，灰化按钮
            btnBuy:setTouchEnabled(false);
            btnBuy:setBright(false);
        else
            -- 需要叹号提示
            playBubbleAnima(hint2, false);
        end
    elseif "SkyPetShop" == openType then
        btnBuy:setTitleText(getLocStr("btn_text_recruit2"));
        btnBuy:setVisible(true);
        checkBlueBubbleStatus(hintNode, false);
        if not SkyPetShopM.canExchangeGoods(self.goodsId) then
            -- 无法兑换，灰化按钮
            btnBuy:setTouchEnabled(false);
            btnBuy:setBright(false);
        end
    elseif "activity" == self.openType then
        -- 活动本公告，只留下返回
        btnBuy:setVisible(false);
        btnComment:setVisible(false);
    elseif "activityShop" == self.openType then
        -- 活动商店
        btnBuy:setTitleText(getLocStr("btn_text_recruit2"));
        btnBuy:setVisible(true);
        checkBlueBubbleStatus(hintNode, false);
        local activityId = ActivityM.queryExchange(self.goodsId, "activity");
        if true ~= ActivityM.canExchange(activityId, self.goodsId, 1) then
            -- 无法兑换，灰化按钮
            btnBuy:setTouchEnabled(false);
            btnBuy:setBright(false);
        end
    else
        btnBuy:setVisible(false);
    end
    TextStyleM.setTextStyle(btnBuy, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);

    -- 评论数量
    self:checkCommentCount();
end

-- 检查评论数量
function UIHeroDetailInfo:checkCommentCount()
    -- 评论按钮
    local btnComment = findChildByName(self.node, "BT/btn_comment");
    local commentLabel = findChildByName(btnComment, "comment_label");
    local hintNode = findChildByName(btnComment, "hint");
    local commentType = "pet_" .. tostring(self.classId);
    local count = CommentM.getCommentCount(commentType);
    local kerning = 0;
    if getLang() == "zh" or getLang == "tw" then
        kerning = 4;
    end
    TextStyleM.setTextStyle(commentLabel, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true, kerning, nil, nil, nil, nil, true);
    btnComment:setTitleText("");
    commentLabel:setString(string.format(getLocStr("btn_text_comment_num"), count));
end

-- 创建英雄模型
function UIHeroDetailInfo:createHeroModel()
    local headImg = findChildByName(self.node, "CT/hero_bg/hero_node/hero_image");
    local modelNode = findChildByName(self.node, "CT/hero_bg/hero_node/model_node");

    -- 获取当前出战英雄
    local icon;
    local modelId;

    if self.hero then
        icon = self.hero:getLargeIcon();
        modelId = self.hero:getModelId();
    else
        icon = PetM.getDefaultLargeIcon(self.classId);
        modelId = PetM.query(self.classId, "default_model");
    end

    local iconPath = getHeroLargeIconPath(icon);

    local petScaleAndPos = PetM.getPetScaleAndPos(self.classId, "detail");
    headImg:setScale(headImg:getScale() * petScaleAndPos["scale"]);
    headImg:setPositionX(headImg:getPositionX() + petScaleAndPos["offset_x"]);
    headImg:setPositionY(headImg:getPositionY() + petScaleAndPos["offset_y"]);

    createHeroModel(modelId, headImg, modelNode, HERO_MODEL_SCALE, iconPath);
end

-- 属性初始化
function UIHeroDetailInfo:initProp()
    local names = {"attack", "hp", "magic", "mp"};
    local values;

    if self.hero then
        values = {self.hero:getAttack(), self.hero:getMaxHp(), self.hero:getMagic(), self.hero:getMaxMp()};
    else
        local initAttrib = PetM.getPetInitRankAttrib(self.classId);
        values = {initAttrib["attack"], initAttrib["max_hp"], initAttrib["magic"], initAttrib["max_mp"], };
    end

    for i = 1, #names do
        local nameLabel = findChildByName(self.node, "CT/hero_bg/info_node/bg"..tostring(i).."/name");
        TextStyleM.setTextStyle(nameLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, false, -1);
        nameLabel:setString(getLocStr(names[i]));

        local valueLabel = findChildByName(self.node, "CT/hero_bg/info_node/bg"..tostring(i).."/value");
        TextStyleM.setTextStyle(valueLabel, TextStyleM.TEXT_SIZE_SMALL2, TextStyleM.TEXT_COLOR_BEIGE, false, -1);
        valueLabel:setString(values[i]);
    end
end

-- 重绘天赋
function UIHeroDetailInfo:redrawTalentInfo()
    local talentNode = findChildByName(self.scrollview, "info_3");
    local propNameLabel = findChildByName(talentNode, "name_label");
    local talentIcon = findChildByName(talentNode, "type_img");
    local skillId1;

    if self.hero then
        skillId1 = self.hero:getTalentSkillId();
    else
        skillId1 = PetM.query(self.classId, "talent");

        skillId1 = skillId1 + PetM.query(self.classId, "init_rank") - 1;
    end

    -- 天赋图标/使用冈布奥的头像
    local icon;
    if self.hero then
        icon = self.hero:getIcon();
    else
        icon = PetM.getDefaultIcon(self.classId);
    end

    local iconPath   = getSmallHeroIconPath(icon);
    talentIcon:loadTexture(iconPath);

    -- 天赋名称
    local skillName = SkillM.query(skillId1, "name");
    TextStyleM.setTextStyle(propNameLabel, TextStyleM.TEXT_SIZE_SMALL, TextStyleM.TEXT_COLOR_DARK_RED, nil, nil, nil, nil, nil, nil, nil, TextStyleM.getTextScale(skillName, 36));
    propNameLabel:setString(skillName);

    -- 注册点击事件
    local detailImg = findChildByName(talentNode, "detail_img");
    detailImg:setVisible(true);
    local function onDetailClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            AudioM.playFx("button_caption");
            -- 显示技能操作页面
            if UIMgr.getCurrentScene():isOpen("UISkillOperation") then
                UIMgr.getCurrentScene():removeFormByName("UISkillOperation");
            end

            local uiSkillOperation = UISkillOperation.create(skillId1);
            UIMgr.getCurrentScene():addForm(uiSkillOperation);
        end
    end
    detailImg:addTouchEventListener(onDetailClick);
end

-- 重绘专属技能
function UIHeroDetailInfo:redrawSpecialInfo()
    local talentNode = findChildByName(self.scrollview, "info_4");
    local propNameLabel = findChildByName(talentNode, "name_label");
    local skillIcon = findChildByName(talentNode, "type_img");

    local skillId2;

    if self.hero then
        skillId2 = self.hero:query("special");
    else
        skillId2 = PetM.query(self.classId, "special");
    end

    -- 技能图标
    -- 天赋图标/使用冈布奥的头像
    local icon;
    if self.hero then
        icon = self.hero:getIcon();
    else
        icon = PetM.getDefaultIcon(self.classId);
    end
    local iconPath = getSmallHeroIconPath(icon);
    skillIcon:loadTexture(iconPath);

    -- 技能名称
    TextStyleM.setTextStyle(propNameLabel, TextStyleM.TEXT_SIZE_SMALL, TextStyleM.TEXT_COLOR_DARK_RED);
    propNameLabel:setString(SkillM.query(skillId2, "name"));

    -- 注册点击事件
    local detailImg = findChildByName(talentNode, "detail_img");
    detailImg:setVisible(true);
    local function onDetailClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            AudioM.playFx("button_caption");
            -- 显示技能操作页面
            if UIMgr.getCurrentScene():isOpen("UISkillOperation") then
                UIMgr.getCurrentScene():removeFormByName("UISkillOperation");
            end

            local uiSkillOperation = UISkillOperation.create(skillId2);
            UIMgr.getCurrentScene():addForm(uiSkillOperation);
        end
    end
    detailImg:addTouchEventListener(onDetailClick);
end

-- 设置滚动容器项
function UIHeroDetailInfo:initScrollview()
    local scrollview = findChildByName(self.node, "CT/scrollview");
    scrollview:removeAllChildren();

    local itemNode = cc.CSLoader:createNode("layout/hero/HeroDetailInfoNode.csb");
    local widget = replaceNodeWithWidget(itemNode);

    -- 左边距
    local leftMargin = 1;

    -- 行间距
    local gap = 0;
    local widgetHeight = 61;

    -- 先固定行数为5
    local totalNum = 5;

    local startHeight = 10;

    --计算总高度
    local totalHeight = math.max(totalNum * (widgetHeight + gap), scrollview:getInnerContainerSize().height);
    startHeight = totalHeight;

    if totalHeight < scrollview:getInnerContainerSize().height then
        startHeight = scrollview:getInnerContainerSize().height;
    end

    scrollview:setInnerContainerSize(cc.size(scrollview:getInnerContainerSize().width, totalHeight));

    local itemName = "info_";
    for n = 1, 5 do
        local child = widget:clone();
        child:setName(itemName .. n);

        local x = leftMargin;
        local y = startHeight - n * (widgetHeight + gap) - 10;

        if n == 1 then
            local line2 = findChildByName(child, "line2");
            line2:setVisible(true);
        end

        child:setPositionX(x);
        child:setPositionY(y);

        scrollview:addChild(child);
    end
end

resize = function(self)
    local node = self.node;

    -- bg居中显示并充满整个屏幕
    AlignM.fitToScreen(node, "bg");

    -- CT居中并缩放至合适大小
    AlignM.alignToCenter(node, "CT");

    -- BT置于底部并缩放至合适大小
    AlignM.alignToBottomCenter(node, "BT");
end
